﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using shuatibao.Constance;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace shuatibao.Tool
{

    public class WechatTool
    {
        public object WechatConstance { get; set; }

    


        #region ============ 微信小程序 ===============

        public static WechatJSCode2SessionModel getcode2SessionManager(string jsCode)
        {

            WechatJSCode2SessionModel sessionModel = new WechatJSCode2SessionModel();
            string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + ConstanceWechat.smallCeshibaoAppId + "&secret=" + ConstanceWechat.smallCeshibaoAppSecret + "&js_code=" + jsCode + "&grant_type=authorization_code";
            string info = InterfaceManager.HttpGet(url, "");

            JObject jo = (JObject)JsonConvert.DeserializeObject(info);
            if (jo.Property("errcode") == null || jo.Property("errcode").ToString() == "")
            {
                string session_key = jo["session_key"].ToString();
                string openid = jo["openid"].ToString();
                string unionid = jo["unionid"].ToString();
                sessionModel.openid = openid;
                sessionModel.session_key = session_key;
                sessionModel.unionid = unionid;
            }
            else
            {
                string errcode = jo["errcode"].ToString();
            }

            return sessionModel;

        }


        #region 微信授权- 获取用户信息
        public string getUserInfoWithTokenOpenId(string token, string openId)
        {
            string nUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" + token + "&openid=" + openId + "&lang=zh_CN";

            return InterfaceManager.HttpGet(nUrl, "");
        }
        #endregion

        #endregion
    }



    #region 微信推送Model
    public class WechatNoticeModel
    {


        public WechatNoticeTempModel const15 { get; set; }   // 产品名称

        public WechatNoticeTempModel time3 { get; set; }   // 产品名称
        public WechatNoticeTempModel amount2 { get; set; }   // 产品名称

        public WechatNoticeTempModel thing2 { get; set; }   // 产品名称

        public WechatNoticeTempModel thing3 { get; set; }   // 产品名称
        public WechatNoticeTempModel thing4 { get; set; }   // 产品名称
        public WechatNoticeTempModel thing6 { get; set; }   // 产品名称
        public WechatNoticeTempModel thing7 { get; set; }   // 产品名称

        public WechatNoticeTempModel thing8 { get; set; }   // 产品名称
        public WechatNoticeTempModel thing13 { get; set; }   // 产品名称


        public WechatNoticeTempModel character_string2 { get; set; }   //  订单编号
        public WechatNoticeTempModel amount5 { get; set; }   //  付款金额
        public WechatNoticeTempModel amount28 { get; set; }   //  订单佣金
        public WechatNoticeTempModel amount17 { get; set; }   //  订单佣金

        public WechatNoticeTempModel phrase20 { get; set; }   //  支付方式
        public WechatNoticeTempModel time6 { get; set; }   //  支付方式
        public WechatNoticeTempModel time2 { get; set; }   //  支付方式
        public WechatNoticeTempModel character_string10 { get; set; }   //  支付方式
        public WechatNoticeTempModel character_string1 { get; set; }   //  支付方式
        public WechatNoticeTempModel amount3 { get; set; }   //  支付方式




    }


    public class WechatNoticeTempModel
    {
        public string value { get; set; }
        public string color { get; set; }
    }

    public class WechatNoticeMiniprogramModel
    {
        public string appid { get; set; }
        public string pagepath { get; set; }


    }

    public class WechatNoticeMainModel
    {

        public string touser { get; set; }
        public string template_id { get; set; }
        public string url { get; set; }
        public string appid { get; set; }
        public WechatNoticeModel data { get; set; }
        public WechatNoticeMiniprogramModel miniprogram { get; set; }



    }

    #endregion


    public class WechatJSCode2SessionModel
    {
        public string openid { get; set; }
        public string session_key { get; set; }
        public string unionid { get; set; }
        public string main_union_id { get; set; }

    }

    public class WechatJSCode2SessionDataModel
    {

        public WechatJSCode2SessionModel data { get; set; }
        public string code { get; set; }
        public string msg { get; set; }

    }











}